package office.service.hr.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import office.action.hr.form.CarriageManageForm;
import office.action.hr.wrapper.CarriageManageWrapper;
import office.bo.hr.ICarriageManage;
import office.bo.hr.impl.CarriageManage;
import office.domainset.BizDomainProviderSetImpl;
import office.service.hr.ICarriageManageService;
import platform.common.exception.BusinessException;
import platform.common.service.impl.BaseBizServiceImpl;
import platform.util.Util;

public class CarriageManageServiceImpl extends BaseBizServiceImpl implements ICarriageManageService{
	/**
	 * 根据状态获取车辆信息
	 * @param state
	 * @return
	 * @throws BusinessException
	 */
	public List getCarriageManageByState(String state) throws BusinessException{
		List listData = new ArrayList();
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			Map qryParamMap = new HashMap();
			qryParamMap.put("state", state);
			listData = domainProviderSetImpl.getDao().findByHqlNameAndDomian(domainProviderSetImpl.getCarriageManageDP(), "carriageManageByState", qryParamMap);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据状态获取车辆信息失败!", e);
		}
		return listData;
	}

	/**
	 * 获取车辆信息
	 * @return
	 * @throws BusinessException
	 */
	public List getCarriageManageList() throws BusinessException{
		List listData = new ArrayList() ;
		try {
			Map mapCarriageType = Util.parsePropertiesReturnMap("office","carriageType.size");
			Map mapCarriageSate = Util.parsePropertiesReturnMap("office","carriageSate.size");
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			List list = domainProviderSetImpl.getDao().findAllByDomian(domainProviderSetImpl.getCarriageManageDP());
			CarriageManageWrapper wrapper;
			for(int i=0;i<list.size();i++){
				CarriageManage bo = (CarriageManage)list.get(i);
				wrapper = new CarriageManageWrapper();
				wrapper.copyToWrapper(bo,mapCarriageType,mapCarriageSate);
				listData.add(wrapper);
			}
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("获取车辆信息失败!", e);
		}
		return listData;
	}
	/**
	 * 编辑车辆
	 * @throws BusinessException
	 */
	public void editCarriageManage(CarriageManageForm objctForm)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			CarriageManage bo = null;
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				bo = (CarriageManage)domainProviderSetImpl.getCarriageManageDP().newEmptyObj();
			}else{
				bo = (CarriageManage)domainProviderSetImpl.getDao().findByIdAndDomain(domainProviderSetImpl.getCarriageManageDP(), objctForm.getId());
			}
			bo =(CarriageManage) objctForm.copyPropertiesToBO(bo);
			if(null==bo.getId() || ("").equals(bo.getId())){
				bo.generatorUUID();
			}
			//验证是否存在重复记录
			bo.store(domainProviderSet);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("编辑车辆信息失败!", e);
		}
	}
	/**
	 * 根据id获取对象
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	public CarriageManageForm getById(String id)throws BusinessException{
		CarriageManageForm form = new CarriageManageForm();
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			ICarriageManage bo = (ICarriageManage)domainProviderSetImpl.getDao().findByIdAndDomain(domainProviderSetImpl.getCarriageManageDP(), id);
			form.copyPropertiesFromBO(bo);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id获取车辆信息失败!", e);
		}
		return form;
	}
	/**
	 * 根据id删除对象
	 * @param id
	 * @throws BusinessException
	 */
	public void deleteById(String id)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			domainProviderSetImpl.getDao().deleteById(domainProviderSetImpl.getCarriageManageDP(), id);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id删除车辆信息失败!", e);
		}
	}
	
	/**
	 * 修改车辆状态
	 * @param state
	 * @throws BusinessException
	 */
	public void changeState(CarriageManageForm objctForm) throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			CarriageManage bo = (CarriageManage)domainProviderSetImpl.getDao().findByIdAndDomain(domainProviderSetImpl.getCarriageManageDP(), objctForm.getId());
			bo.setState(objctForm.getState());
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("根据id修改车辆状态信息失败!", e);
		}
	}
}
